﻿using Frame.Core.IServices;
using Frame.Core.Models;
using Frame.Core.Repository;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Frame.Core.Services
{
    public class BaseService<TEntity> :IBaseService<TEntity> where TEntity : class, new()
    {
        public IRepositoryBase<TEntity> BaseDal;//通过在子类的构造函数中注入，这里是基类，不用构造函数

        public async Task<TEntity> GetLeftJoinAsync(Expression<Func<TEntity, bool>> leftJoinExpression, Expression<Func<TEntity, bool>> exp)
        {
            return await BaseDal.GetLeftJoinAsync(leftJoinExpression, exp);
        }

        public async Task<TEntity> GetLeftJoinAsync(Expression<Func<TEntity, bool>> exp)
        {
            return await BaseDal.GetAsync(exp);
        }

        public async Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> exp)
        {
            return await BaseDal.GetAsync(exp);
        }

        public async Task<TDto> GetAsync<TDto>(Expression<Func<TEntity, bool>> exp)
        {
            return await BaseDal.GetAsync<TDto>(exp);
        }
        public async Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> exp)
        {
            return await BaseDal.GetListAsync(exp);
        }
        public async Task<TEntity> AddAsync(TEntity entity)
        {
            return await BaseDal.AddAsync(entity);
        }
        public async Task<IEnumerable<TEntity>> AddAsync(IEnumerable<TEntity> entitys)
        {
            return await BaseDal.AddAsync(entitys);
        }
        public async Task<int> EditAsync(TEntity entity)
        {
            return await BaseDal.EditAsync(entity);
        }
        public async Task<int> AttachEditAsync(TEntity oldobj, TEntity newObj)
        {
            return await BaseDal.AttachEditAsync(oldobj, newObj);
        }

        public async Task<int> EditSingeColumnAsync(Expression<Func<TEntity, object>> setExpression, Expression<Func<TEntity, bool>> exp)
        {
            return await BaseDal.EditSingeColumnAsync(setExpression, exp);
        }

        public async Task<int> DelAsync(Expression<Func<TEntity, bool>> exp)
        {
            return await BaseDal.DeleteAsync(exp);
        }

        public async Task<PagingInfoViewModel<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> whereExpression, PagingInfoViewModel<TEntity> pageInfo, Expression<Func<TEntity, TEntity>> includeExpression = null)
        {
            return await BaseDal.QueryAsync(whereExpression, pageInfo, includeExpression);
        }
    }
}
